﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using CORE = Cosmos.Core;

namespace DimOS.GC
{
    public static class Heap
    {
        private static readonly List<uint> Sizes = new List<uint>(); 
        public static uint MemoryUsed
        { get { return Sizes.Count != 0 ? Sizes[Sizes.Count - 1] : CORE.Heap.GetMemoryUse(); } }

        public static void Monitor() { Sizes.Add(CORE.Heap.GetMemoryUse()); }

        public static void Revoke() { Sizes.RemoveAt(Sizes.Count - 1); }

        public static void Reclaim()
        {
            if (Sizes.Count != 0)
            {
                CORE.Heap.DecreaseMemoryUse(CORE.Heap.GetMemoryUse() - MemoryUsed);
                Sizes.RemoveAt(Sizes.Count - 1);
            }
        }
    }
}
